<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>首页</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta http-equiv="Access-Control-Allow-Origin" content="*">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="format-detection" content="telephone=no">
		<link rel="icon" href="/static/images/favicon.ico">
		<link rel="stylesheet" href="/static/lib/layui-v2.6.3/css/layui.css" media="all">
		<style id="layuimini-bg-color">
			div img {
				width: 100%;
				height: 100%;
				transition: all 0.5s;
			}

			div img:hover {
				transform: scale(1.1);
			}
		</style>
	</head>
	<body>
		<div class="layui-fluid"
			style="background-color: cyan;height: 60px;background-image: url(/static/images/loginbg.png);">
			<div class="layui-row">
				<div class="layui-col-sm6">
					<div class="grid-demo">
						<ul id="menu" class="layui-nav" style="background-color:transparent;">
							<li class="layui-nav-item" value="0"><a href="/">首页</a></li>
						</ul>
					</div>
				</div>
				<div class="layui-col-sm6">
					<div class="grid-demo">
						<ul id="not_login" class="layui-nav"
							style="background-color:transparent;float: right;display:block">
							<li class="layui-nav-item">
								<a href="">vip</a>
							</li>
							<li class="layui-nav-item">
								<a href="/login.html">登录</a>
							</li>
							<li class="layui-nav-item">
								<span>|</span>
							</li>
							<li class="layui-nav-item">
								<a href="">注册</a>
							</li>
						</ul>
						<ul id="login" class="layui-nav" style="background-color:transparent;float: right;display:none">
							<li class="layui-nav-item">
								<a id="vip" href="/web_profile.html?value=2"></a>
							</li>
							<li class="layui-nav-item">
								<a id="user_name" href=""></a>
								<dl class="layui-nav-child">
									<dd>
										<a href="/web_profile.html?value=1"
											layuimini-content-href="page/user-setting.html" data-title="基本资料"
											data-icon="fa fa-gears">基本资料<span class="layui-badge-dot"></span></a>
									</dd>
									<dd>
										<a href="/web_profile.html?value=4"
											layuimini-content-href="page/user-password.html" data-title="修改密码"
											data-icon="fa fa-gears">修改密码</a>
									</dd>
									<dd>
										<hr>
									</dd>
									<dd>
										<a href="javascript:;" class="login_out">退出登录</a>
									</dd>
								</dl>
							</li>
						</ul>
					</div>
				</div>
			</div>
		</div>
		<br />


		<script src="/static/lib/layui-v2.6.3/layui.js"></script>

		<script>
			function getCookie(name) {
				var r = document.cookie.match("\\b" + name + "=([^;]*)\\b");
				return r ? r[1] : undefined;
			}

			function getlocalURL() {
				var localURL = window.location.href;
				var url = localURL.split("&")
				return url[0]
			}

			function getQueryString(name) {
				var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
				var r = window.location.search.substr(1).match(reg);
				if (r != null) {
					return decodeURI(r[2]);
				}
				return '';
			}

			var alipayData = document.location.search.substr(1)

			layui.use(['form', 'layedit', 'laydate', 'flow', 'element', 'layer'], function() {
				var form = layui.form,
					layer = layui.layer,
					layedit = layui.layedit,
					laydate = layui.laydate,
					flow = layui.flow,
					element = layui.element,
					upload = layui.upload,
					table = layui.table,
					$ = layui.jquery;


				var avatar_img = "";
				//检查登录状态
				$.ajax({
					type: "post", //get或者post
					headers: {
						'X-CSRFToken': getCookie('csrf_token')
					},
					url: '/api/v1.0/check_login',
					data: {}, //参数 接口传参 json对象
					success: function(res) {
						// console.log(res);
						if ("0" == res.code) {
							if (res.data.user_id == "1") {
								location.href = "/"
							} else {
								// location.href = "/web_index.html"
								avatar_img = res["data"]["avatar"]
								is_vip = res["data"]["is_vip"]
								console.log(res["data"]["avatar"]);
								console.log(res["data"]["is_vip"]);
								var not_login = document.getElementById('not_login');
								not_login.style.display = 'none'
								var login = document.getElementById('login');
								login.style.display = 'block'
								var a = document.getElementById('user_name'); //获取a元素对象
								if (avatar_img == "") {
									a.innerHTML = '<img src="' + '//t.cn/RCzsdCq' +
										'" class="layui-nav-img">' +
										res.data.user_name;
								} else {
									a.innerHTML = '<img src="' + avatar_img +
										'" class="layui-nav-img">' +
										res.data.user_name;
								}
								var avip = document.getElementById('vip'); //获取a元素对象
								if (is_vip == 1) {
									avip.innerHTML = '<img src="/static/images/vipicon-5.png"/>';

								} else {
									avip.innerHTML = 'vip';
								}
							}

						} else {
							$(".not_login").show();
						}
					}
				});

				//菜单地址添加到li标签中
				function addli_dl(key, value) {
					var li = document.createElement("li")
					li.className = "layui-nav-item"
					li.value = key
					li.innerHTML = '<a href="/web_courselist.html?contents=' + key + '">' + value +
						'</a>'
					document.getElementById("menu").appendChild(li)
					return li
				}

				//获取所有menu菜单
				$.ajax({
					type: "post", //get或者post
					contentType: 'application/json',
					headers: {
						'X-CSRFToken': getCookie('csrf_token')
					},
					url: '/api/v1.0/get_contents_all_list',
					data: {}, //参数 接口传参 json对象
					success: function(res) {
						$("#menu").find('span.layui-nav-bar').remove();
						var li;
						var dl = document.createElement("dl");
						dl.className = "layui-nav-child";

						$.each(res.data, function(index, value) {
							if (value.contents_level == "0") {
								li = addli_dl(value.contents_id, value
									.contents_name)
							}
							if (value.contents_level != "0") {

								$.each(res.data, function(index, valueparent) {
									// console.log(valueparent.contents_level)
									if (value.contents_level ==
										valueparent
										.contents_id) {
										var dd = document.createElement(
											"dd")
										dd.value = valueparent
											.contents_id
										dd.innerHTML =
											'<a href="/web_courselist.html?contents=' +
											value
											.contents_id + '">' + value
											.contents_name +
											'</a>'
										dl.appendChild(dd)
									}

									li.appendChild(dl)

								})
							}
						});
						element.render('ul');
						element.render('dl');

					}
				});


				layer.open({
					type: 1,
					title: false,
					closeBtn: false,
					area: '300px;',
					shade: 0.8,
					btn: ['确定'],
					btnAlign: 'c',
					content: '<div style="padding: 50px; line-height: 22px; background-color: #393D49; color: #fff; font-weight: 300;">已经完成支付，点击【确定】后，视频资料即将发送到您的邮箱并跳转至购买记录页面<br></div>',
					yes: function(index) {
						// var result;
						$.ajax({
							type: "post", //get或者post
							headers: {
								'X-CSRFToken': getCookie('csrf_token')
							},
							url: '/api/v1.0/orderPayment',
							data: alipayData, //参数 接口传参 json对象
							success: function(res) {
								layer.msg('邮件发送成功', function() {
									location.href = "/web_profile.html?value=3"
								});
							},

						});
					},
				});




				//登出操作
				$('.login_out').on("click", function() {
					$.ajax({
						type: "post", //get或者post
						headers: {
							'X-CSRFToken': getCookie('csrf_token')
						},
						url: '/api/v1.0/logout',
						data: {}, //参数 接口传参 json对象
						success: function(res) {
							if (res.code == "0") {
								layer.msg('退出登录成功', function() {
									// window.location = '/login.html';
									// location.href = "/login.html"
									location.href = "/web_index.html"
									// window.location.reload()
								});
							} else {
								layer.msg('退出失败')
							}
						}
					});
				});

			})
		</script>

	</body>
</html>
